#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <SDL2/SDL.h>
#include <QDebug>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);


    SDL_version ver;

    SDL_VERSION(&ver);

    qDebug() << ver.major << ":" << ver.minor << ":" << ver.patch;

}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{

    qDebug()<< "main thread: " << QThread::currentThread();
    if(this->playPCMThread == nullptr) {

        playPCMThread = new PlayPCMThread(10,this);
        playPCMThread->start();

        connect(playPCMThread,&QThread::finished,this,[this](){

            ui->pushButton->setText("开始");
            playPCMThread = nullptr;
            ui->label->setText(nullptr);
        });

        connect(playPCMThread,&PlayPCMThread::callBack,this,[this](int count) {


            ui->label->setText(QString::number(count));

//            qDebug()<< "callBack:" <<  QThread::currentThread();
        });

        ui->pushButton->setText("暂停");
    }else {

        playPCMThread->requestInterruption();

    }

}
